package com.hanrui.android.activity.message.audit;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.hanrui.android.R;
import com.hanrui.android.adapter.VoteDetailLcAdapter;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.VoteDetailBean;
import com.hanrui.android.net.contract.message.audit.proposal.VoteDetailContract;
import com.hanrui.android.net.presenter.message.audit.proposal.VoteDetailPresenter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 表决明细
 */
public class VoteDetailActivity extends ActionBarBaseActivity<VoteDetailPresenter> implements VoteDetailContract.View {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;

    VoteDetailLcAdapter adapter;

    String mid;

    @Override
    protected void initInjector() {mActivityComponent.inject(this);}


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recyclerview_base);

        unbinder = ButterKnife.bind(this);

        mTitleBar.setTitle("表决明细");

        mid = getIntent().getStringExtra("mid");


        recyclerView.setBackgroundColor(ContextCompat.getColor(this,R.color.c_f1f1f1));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new VoteDetailLcAdapter();
        recyclerView.setAdapter(adapter);


        setIsPullRefresh(true);
        setRefreshing();
        mPresenter.loadData(this,mid);

        setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                mPresenter.loadData(VoteDetailActivity.this,mid);

            }
        });

    }


    public static void start(Context context,String mid){
        Intent intent = new Intent(context,VoteDetailActivity.class);
        intent.putExtra("mid",mid);
        context.startActivity(intent);
    }

    @Override
    public void loadData(List<VoteDetailBean.ResultListBean> dataList, int loadType) {

        closeResresh();
        if (null != dataList && dataList.size() > 0) {

            adapter.setNewData(dataList);
        }

    }
}
